//
//  UIimageView+Extension.swift
//  Swift微博
//
//  Created by 陈竹 on 16/2/26.
//  Copyright © 2016年 陈竹. All rights reserved.
//

import UIKit
import SDWebImage

extension UIImageView{
    
    convenience init(cz_imageName imageName:String) {
        self.init(image: UIImage(named: imageName))
    }
    
    func cz_setImageWithURL(urlString:String?,placeholderName:String?){
        //如果有占位图就创建占位图片
        var placeholderImage:UIImage?
        if let placeholderName = placeholderName{
            placeholderImage=UIImage(named: placeholderName)
        }
        
        //如果没有图片url就设置占位图片
        guard let urlString=urlString ,
            let url=NSURL(string: urlString) else{
                image=placeholderImage
                return
        }
        //使用框架加载网络图片
        sd_setImageWithURL(url, placeholderImage: placeholderImage)
        
    }
}

